﻿<Window x:Class="JsEditor.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sh="clr-namespace:SyntaxHighlight;assembly=SyntaxHighlight" Loaded="Window_Loaded"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <sh:SyntaxRuleCollection x:Key="LightSyntax">
            <sh:SyntaxRuleItem RuleType="Keyword" Foreground="Blue" />
            <sh:SyntaxRuleItem RuleType="Number" Foreground="DarkCyan"  />
            <sh:SyntaxRuleItem RuleType="Comment" Foreground="Green" />
            <sh:SyntaxRuleItem RuleType="String" Foreground="DarkRed"  />
        </sh:SyntaxRuleCollection>

        <sh:SyntaxRuleCollection x:Key="DarkSyntax">
            <sh:SyntaxRuleItem RuleType="Keyword" Foreground="Yellow" />
            <sh:SyntaxRuleItem RuleType="Number" Foreground="Cyan"  />
            <sh:SyntaxRuleItem RuleType="Comment" Foreground="LightGreen" />
            <sh:SyntaxRuleItem RuleType="String" Foreground="Red"  />
        </sh:SyntaxRuleCollection>

        <sh:SyntaxRuleCollection x:Key="ExperimentalSyntax">
            <sh:SyntaxRuleItem RuleType="Keyword" >
                <sh:SyntaxRuleItem.Foreground>
                    <LinearGradientBrush>
                        <GradientStop Color="Blue" Offset="0" />
                        <GradientStop Color="LightBlue" Offset="1"/>
                    </LinearGradientBrush>
                </sh:SyntaxRuleItem.Foreground>
            </sh:SyntaxRuleItem>
            <sh:SyntaxRuleItem RuleType="Number" >
                <sh:SyntaxRuleItem.Foreground>
                    <LinearGradientBrush>
                        <GradientStop Color="DarkCyan" Offset="0" />
                        <GradientStop Color="Cyan" Offset="1"/>
                    </LinearGradientBrush>
                </sh:SyntaxRuleItem.Foreground>
            </sh:SyntaxRuleItem>
            <sh:SyntaxRuleItem RuleType="Comment" >
                <sh:SyntaxRuleItem.Foreground>
                    <LinearGradientBrush>
                        <GradientStop Color="Green" Offset="0" />
                        <GradientStop Color="LightGreen" Offset="1"/>
                    </LinearGradientBrush>
                </sh:SyntaxRuleItem.Foreground>
            </sh:SyntaxRuleItem>
            <sh:SyntaxRuleItem RuleType="String" >
                <sh:SyntaxRuleItem.Foreground>
                    <LinearGradientBrush>
                        <GradientStop Color="Red" Offset="0" />
                        <GradientStop Color="LightPink" Offset="1"/>
                    </LinearGradientBrush>
                </sh:SyntaxRuleItem.Foreground>
            </sh:SyntaxRuleItem>
        </sh:SyntaxRuleCollection>

        <SolidColorBrush x:Key="DarkForeground" Color="Black" />

        <SolidColorBrush x:Key="LightForeground" Color="LightGray" />

        <LinearGradientBrush x:Key="LightBackground">
            <LinearGradientBrush.RelativeTransform>
                <RotateTransform Angle="90"></RotateTransform>
            </LinearGradientBrush.RelativeTransform>
            <GradientStop Color="White" Offset="0" />
            <GradientStop Color="Gray" Offset="1"/>
        </LinearGradientBrush>

        <Storyboard x:Key="ExperimentalStoryBoard">
            <ColorAnimation From="White" To="Gray" Duration="0:0:5.0" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="BackgroundBrush.GradientStops[0].Color"  />
            <ColorAnimation From="Gray" To="White" Duration="0:0:5.0" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="BackgroundBrush.GradientStops[1].Color"  />
        </Storyboard>

        <LinearGradientBrush x:Key="DarkBackground">
            <LinearGradientBrush.RelativeTransform>
                <RotateTransform Angle="80"></RotateTransform>
            </LinearGradientBrush.RelativeTransform>
            <GradientStop Color="#222222" Offset="0" />
            <GradientStop Color="Black" Offset="1"/>
        </LinearGradientBrush>

        <Style x:Key="DarkTheme" TargetType="sh:SyntaxHighlightTextBox">
            <Setter Property="CursorColor" Value="White" />
            <Setter Property="BackgroundBrush" Value="{StaticResource DarkBackground}"/>
            <Setter Property="ForegroundBrush" Value="{StaticResource LightForeground}" />
            <Setter Property="LineNumberBrush" Value="{StaticResource LightForeground}" />
            <Setter Property="SyntaxRules" Value="{StaticResource DarkSyntax}" />
        </Style>

        <Style x:Key="LightTheme" TargetType="sh:SyntaxHighlightTextBox">
            <Setter Property="CursorColor" Value="Black" />
            <Setter Property="BackgroundBrush" Value="{StaticResource LightBackground}"/>
            <Setter Property="ForegroundBrush" Value="{StaticResource DarkForeground}" />
            <Setter Property="LineNumberBrush" Value="{StaticResource DarkForeground}" />
            <Setter Property="SyntaxRules" Value="{StaticResource LightSyntax}" />
        </Style>

        <Style x:Key="ExperimentalTheme" TargetType="sh:SyntaxHighlightTextBox">
            <Setter Property="CursorColor" Value="Green" />
            <Setter Property="BackgroundBrush" Value="{StaticResource LightBackground}"/>
            <Setter Property="ForegroundBrush" Value="{StaticResource DarkForeground}" />
            <Setter Property="LineNumberBrush" Value="{StaticResource DarkForeground}" />
            <Setter Property="SyntaxRules" Value="{StaticResource ExperimentalSyntax}" />
            <Style.Triggers>
                <EventTrigger RoutedEvent="sh:SyntaxHighlightTextBox.SyntaxRulesChanged">
                    <BeginStoryboard  Storyboard="{StaticResource ExperimentalStoryBoard}" />
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <ToolBarTray Grid.Row="0">
            <ToolBar>
                <Menu>

                    <MenuItem Header="File">
                        <MenuItem Header="Examples">
                            <MenuItem x:Name="IronPytonExampleMenuItem" Header="IronPython code" Click="IronPytonExampleMenuItem_Click" />
                            <MenuItem x:Name="BooExampleMenuItem" Header="Boo code" Click="BooExampleMenuItem_Click" />
                        </MenuItem>
                        <Separator/>
                        <MenuItem Header="Exit" Click="MenuItem_Click_1" />
                    </MenuItem>

                    <MenuItem Header="View">
                        <MenuItem Header="Syntax highlight">
                            <MenuItem x:Name="IronPythonMenuItem" Header="IronPython"   Click="IronPythonMenuItem_Click" />
                            <MenuItem x:Name="BooMenuItem" Header="Boo"  IsChecked="True" Click="BooMenuItem_Click" />
                        </MenuItem>
                        <MenuItem Header="Color theme">
                            <MenuItem x:Name="LightThemeMenuItem" Header="Light" Click="LightThemeMenuItem_Click" IsChecked="True"/>
                            <MenuItem x:Name="DarkThemeMenuItem" Header="Dark" Click="DarkThemeMenuItem_Click" />
                            <MenuItem x:Name="ExperimentalThemeMenuItem" Header="Experimental" Click="ExperimentalThemeMenuItem_Click"/>
                        </MenuItem>
                    </MenuItem>


                    <MenuItem Header="Help" >
                        <MenuItem Header="About..." Click="MenuItem_Click" />
                    </MenuItem>

                </Menu>
            </ToolBar>

            <ToolBar HorizontalAlignment="Right">
                <Label>Search:</Label>
                <TextBox x:Name="SearchTextBox" KeyDown="SearchTextBox_KeyDown" Width="150"></TextBox>
            </ToolBar>

        </ToolBarTray >



        <sh:SyntaxHighlightTextBox x:Name="SyntaxTextBox" Grid.Row="1" Style="{StaticResource LightTheme}" >

        </sh:SyntaxHighlightTextBox>
    </Grid>
</Window>
